/*
 * Main.fx
 *
 * Created on 18.11.2009, 23:28:29
 */

package javafx179labs.sorokin.lab2;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.ext.swing.SwingTextField;
import javafx.ext.swing.SwingButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.Group;

/**
 * @author Krazyzy
 */

var fields: Group[] = [];
def buttonWidth = 70;
def buttonHeight = 25;
var field: SwingTextField = SwingTextField {
        columns: 30
        editable: true
    }
var addbutton: SwingButton = SwingButton {
        text: "add"
        width: buttonWidth
        height: buttonHeight
        layoutX: 300
        onMouseClicked: function(e: MouseEvent) {
                insert creator(field.text) into fields
                }
    }

function proced (seq: Group[]) {
        var inc = 0; for (e in seq) {
        e.translateY = inc; inc += 30;
        }
        return seq;
        }   

function creator(str: String) {
    var field: SwingTextField = SwingTextField {
        columns: 30
        text: str
        editable: false
    }

    var button1: SwingButton = SwingButton {
        text: "edit"
        width: buttonWidth
        height: buttonHeight
        layoutX: 300
        onMouseClicked: function(e: MouseEvent) {
                field.editable = not field.editable;
                }
    }


    var button2: SwingButton = SwingButton {
        text: "delete"
        width: buttonWidth
        height: buttonHeight
        layoutX: 370
        onMouseClicked: function(e: MouseEvent) {
                delete name from fields;
                }
    }

      var name: Group = Group {
        content: [field, button1, button2]
    }
return name
}


insert creator("hello world") into fields;
insert creator("hello humans") into fields;

Stage {
       scene: Scene {
    width: 500
    height: 500
        content: [
                field,
                addbutton,
                Group {
                    translateY: 30
                    content: bind [proced(fields)]
                }
        ]
    }
}